package com.vhly.bpplat.twitter.model;

import org.kxml2.kdom.Element;

/**
 * Created by IntelliJ IDEA.
 * User: vhly[FR]
 * Date: 2010-3-3
 * Time: 17:40:22
 */
public class Status implements Model {
    public String create_at;
    public String id;
    public String text;
    public String source;
    public boolean truncated;
    public String reply_to_status_id;
    public String reply_to_user_id;
    public boolean favorited;
    public String reply_to_screen_name;
    public User user;

    public void parse(Element el) {
        String n = el.getName();
        if (n.equals("status")) {
            StringBuffer sb = new StringBuffer();
            Element ca = el.getElement("", "created_at");
            if (ca != null) {
                this.create_at = (String) ca.getChild(0);
            }
            ca = el.getElement("","id");
            if(ca != null){
                id = (String) ca.getChild(0);
            }
            Element etext = el.getElement("", "text");
            if (etext != null) {
                int childCount = etext.getChildCount();
                sb.setLength(0);
                for (int i = 0; i < childCount; i++) {
                    Object obj = etext.getChild(i);
                    if (obj instanceof String) {
                        sb.append((String) obj);
                    }
                }
                text = sb.toString();
                text = text.replaceAll("&","&amp;");
            }
            Element eu = el.getElement("", "user");
            if (eu != null) {
                user = new User();
                user.parse(eu);
            }
        }
    }
}
